#include "map.h"
#include <QDebug>

Map::Map(quint16 mapSize, const QString& map_data) :
    m_width(mapSize), m_mapData(),
    m_wallSample(new Wall()),
    m_bushSample(new Bush()),
    m_terrainSample(new Terrain())
{
    for (int y = 0; y < mapSize; y++)
        for (int x = 0; x < mapSize; x++)
        {
            if (map_data[y*mapSize+x] == 'W' )
            {
                m_mapData.push_back(m_wallSample);
            }
            else if (map_data[y * mapSize + x] =='B')
            {
                m_mapData.push_back(m_bushSample);
            }
            else
            {
                m_mapData.push_back(m_terrainSample);
            }
        }

}

void Map::Render(QGraphicsScene *scene) const
{
    QGraphicsPixmapItem* curr_cell;
    for (int y = 0; y < m_width; y++)
        for (int x = 0; x < m_width; x++)
        {
            int posx = x * PixelsPerCell;
            int posy = y * PixelsPerCell;
            curr_cell = new QGraphicsPixmapItem(ItemAt(y,x)->GetImage());
            curr_cell->moveBy(posx, posy);
            scene->addItem(curr_cell);
        }
}

QVector <int> Map::GetList()
{
    m_mapList.push_back(270);
    m_mapList.push_back(7038);
    m_mapList.push_back(16214);
    m_mapList.push_back(12034);
    m_mapList.push_back(366);
    m_mapList.push_back(12158);
    m_mapList.push_back(16146);
    m_mapList.push_back(3842);

    return m_mapList;
}

Map::~Map()
{
    delete m_wallSample;
    delete m_bushSample;
    delete m_terrainSample;
}
